home *** CD-ROM | disk | FTP | other *** search
/ Nebula 2 / Nebula Two.iso / SourceCode / DeveloperLabs / Lab3 / TextView.m < prev   
Text File  |  1995-06-12  |  2KB  |  84 lines

  1. /*
  2. **  TextView.m, implementation of scrolling text stuff for TextLab.
  3. **  Copyright 1989 NeXT, Inc.  All Rights Reserved.
  4. **  Author: Bruce Blumberg, NeXT Developer Support Group
  5. */
  6.  
  7. #import <appkit/appkit.h>
  8. #import "TextView.h"
  9.  
  10. @implementation TextView:View
  11.  
  12. +newFrame:(const NXRect *)tFrame
  13. {    NXRect rect;
  14.     
  15.     /*            EXERCISE #1                 *
  16.     *    Turn this into a subclass of a ScrollView and set    *
  17.     *    the docView of the scrolling view to the text object     *
  18.     *    returned by the -newText: method of TextView.        *
  19.     *    Before you call newText: you will need to determine the    *
  20.     *    size of the text object you want newText: to create for    *
  21.     *    you. It should be the same size of the scrollView less  *
  22.     *     the size of the scrollers. There is a method of         *
  23.     *    ScrollView which will give you this information. Also     *
  24.     *    note that in a ScrollView you do not have to explicitly *
  25.     *    make the view you are scrolling over (the docView) a    *
  26.     *     subview of the ScrollView. That is done for you when you*
  27.     *     set the docView of the ScrollView            */
  28.  
  29.     /* create view */
  30.     self = [super newFrame:tFrame];
  31.     theText = [self newText:&bounds];
  32.     [self addSubview:theText];
  33.     
  34.     // The following two lines allow the resizing of the view
  35.     // to be passed down to the docView (in this case, the text view 
  36.     // itself).
  37.  
  38.     [[theText superview] setAutoresizeSubviews:YES];
  39.     [[theText superview] setAutosizing:NX_HEIGHTSIZABLE | NX_WIDTHSIZABLE];
  40.  
  41.      // Create enclosing window, display it and bring it upfront
  42.     [self makeEnclosingWindow:tFrame];
  43.     [window makeFirstResponder:theText];
  44.     [window setTitle:"Untitled"];
  45.     [window display];
  46.     [window makeKeyAndOrderFront:self];
  47.     [theText setSel:0:0];    
  48.     return(self);
  49. }
  50.  
  51. -makeEnclosingWindow:(const NXRect *)r
  52. {
  53.     id tWin;
  54.     
  55.     tWin = [Window newContent:r style:NX_TITLEDSTYLE 
  56.         backing:NX_BUFFERED buttonMask:NX_ALLBUTTONS defer:NO];
  57.     [tWin setContentView:self];
  58.     [tWin setBackgroundGray:NX_WHITE];
  59.     [tWin setFreeWhenClosed:YES];
  60.     return self;
  61. }
  62.  
  63. -newText:(const NXRect *)tF
  64. {
  65.     id text = [Text newFrame:tF text:NULL alignment:NX_LEFTALIGNED];
  66.     [text setOpaque:YES];
  67.     [[[[[text notifyAncestorWhenFrameChanged:YES]
  68.         setVertResizable:YES]
  69.         setHorizResizable:NO]
  70.         setMonoFont:NO]
  71.         setDelegate:self];
  72.     
  73.     { NXSize aSize = {1.0E38,1.0E38};
  74.      [text setMinSize:&tF->size];
  75.      [text setMaxSize:&aSize];
  76.         }
  77.     [text setCharFilter:NXEditorFilter];
  78.     return text;
  79. }
  80. @end
  81.     
  82.  
  83.  
  84.